/**
 * 
 */
package com.yinhai.activity;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yinhai.adapter.ContactAdpter;
import com.yinhai.adapter.ContactGroupAdpter;
import com.yinhai.constant.Contact;
import com.yinhai.model.ContactGroup;
import com.yinhai.model.UserUserContact;
import com.yinhai.service.ContactUserServiceImpl;

import android.content.Context;
import android.os.Bundle;
import android.provider.SyncStateContract.Constants;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;


/**
 * @author Juyon
 * 
 */
public class ContactFragment extends Fragment {
	private ListView groupListView;
	private ContactAdpter smsAdpter;
	private ContactUserServiceImpl contactUserService; 
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.main_contact_new, null);
		groupListView = (ListView)view.findViewById(R.id.contact_group_list_item);
		contactUserService = new ContactUserServiceImpl(this.getActivity());
		smsAdpter=new ContactAdpter(this.getActivity());
		
		
//		smsAdpter.assignment(contacts);
		groupListView.setAdapter(smsAdpter);
		groupListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Map<String, String> map = new HashMap<String, String>();
				ContactGroup contactGroup = (ContactGroup) smsAdpter.getItem(position);
				FragmentTransaction transaction = getActivity().getSupportFragmentManager()
						.beginTransaction();
				Fragment fragment = new ContactListFragment();
				Bundle bundle = new Bundle();
				bundle.putString("contactGroupId", contactGroup.getGroupId());
				fragment.setArguments(bundle);
				transaction.replace(R.id.container, fragment);
				transaction.commit();
			}
		});
		return view;
	}
	// 查询的内容 ,1为按 分组查询,2位按联系人姓名,groupId分组ID
	private List<UserUserContact> found(String content,String isGroup,String groupId) {
		//获取集团通讯录
		        List<UserUserContact> list = null;
				if(Contact.IS_GROUP.equals(isGroup)) {
					//按分组名称查询
					list = contactUserService.searchGroup(content);
				} else if(Contact.IS_PERSON.equals(isGroup)) {
					//按姓名查询
				}
				
//				
				return list;
	}
	
}
